from flask import Flask

from App.apis import init_api
from App.ext import init_ext
from App.middleware import load_middleware
from App.settings import envs, TEMPLATE_FOLDER


def create_app():
    app = Flask(__name__ , template_folder=TEMPLATE_FOLDER)
    # app = Flask(__name__ , template_folder='../templates')
    app.config.from_object(envs.get("develop"))
    # print(app.config.from_object)
    # app.config['ENV'] = 'develop'
    # print(app.config.from_object)
    # app.config['JSON_AS_ASCII'] = False           #使用jsonify做返回时候使得汉字不被转码(ascii)
    app.config.update(RESTFUL_JSON=dict(ensure_ascii=False))    #使用flask_restful做返回的时候使得汉字不被转码(ascii)

    init_api(app)           #各种插件;跟路由相关的拉到appinit这里来写，其他的都可以放在ext里
    init_ext(app)           #初始化第三方库
    load_middleware(app)    #加载中间件

    return app

